package com.platform.usercenter.controller;

import com.platform.common.core.utils.poi.ExcelUtil;
import com.platform.common.core.web.controller.BaseController;
import com.platform.common.core.web.domain.AjaxResult;
import com.platform.common.core.web.page.TableDataInfo;
import com.platform.common.security.annotation.RequiresPermissions;
import com.platform.usercenter.domain.SysRoleMenuValue;
import com.platform.usercenter.service.ISysRoleMenuValueService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 角色菜单数据权限Controller
 *
 * @author platform
 * @date 2024-10-28
 */
@RestController
@RequestMapping("/rolePreValue")
public class SysRoleMenuValueController extends BaseController {
    @Resource
    private ISysRoleMenuValueService sysRoleMenuValueService;

    /**
     * 查询角色菜单数据权限列表
     */
    @RequiresPermissions("usercenter:rolePreValue:list")
    @GetMapping("/list")
    public TableDataInfo list(SysRoleMenuValue sysRoleMenuValue) {
        startPage();
        List<SysRoleMenuValue> list = sysRoleMenuValueService.selectSysRoleMenuValueList(sysRoleMenuValue);
        return getDataTable(list);
    }

    /**
     * 导出角色菜单数据权限列表
     */
    @RequiresPermissions("usercenter:rolePreValue:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysRoleMenuValue sysRoleMenuValue) {
        List<SysRoleMenuValue> list = sysRoleMenuValueService.selectSysRoleMenuValueList(sysRoleMenuValue);
        ExcelUtil<SysRoleMenuValue> util = new ExcelUtil<>(SysRoleMenuValue.class);
        util.exportExcel(response, list, "角色菜单数据权限数据");
    }

    /**
     * 获取角色菜单数据权限详细信息
     */
    @RequiresPermissions("usercenter:rolePreValue:query")
    @GetMapping(value = "/{orgId}")
    public AjaxResult getInfo(@PathVariable("orgId") Long orgId) {
        return success(sysRoleMenuValueService.selectSysRoleMenuValueByOrgId(orgId));
    }

    /**
     * 新增角色菜单数据权限
     */
    @RequiresPermissions("usercenter:rolePreValue:add")
    @PostMapping
    public AjaxResult add(@RequestBody SysRoleMenuValue sysRoleMenuValue) {
        return toAjax(sysRoleMenuValueService.insertSysRoleMenuValue(sysRoleMenuValue));
    }

    /**
     * 修改角色菜单数据权限
     */
    @RequiresPermissions("usercenter:rolePreValue:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody SysRoleMenuValue sysRoleMenuValue) {
        return toAjax(sysRoleMenuValueService.updateSysRoleMenuValue(sysRoleMenuValue));
    }

    /**
     * 删除角色菜单数据权限
     */
    @RequiresPermissions("usercenter:rolePreValue:remove")
    @DeleteMapping("/{orgIds}")
    public AjaxResult remove(@PathVariable Long[] orgIds) {
        return toAjax(sysRoleMenuValueService.deleteSysRoleMenuValueByOrgIds(orgIds));
    }
}
